package com.springboot.wisdom.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.springboot.wisdom.common.common.bean.DeleteDTO;
import com.springboot.wisdom.common.common.bean.MyResult;
import com.springboot.wisdom.common.common.bean.PageQueryDTO;
import com.springboot.wisdom.serviceApi.system.model.dto.RoleDTO;
import com.springboot.wisdom.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description
 * @Author LY L
 * @Date 2024-11-03
 */
@Api(tags = "系统管理模块【角色管理】")
@ApiSupport(author = "LY L")
@RestController
@RequestMapping(value = "/system/role", produces = {"application/json;charset=UTF-8"})
@Slf4j
//@Validated     // springboot 2.5.* 版本需要在类上标注 @Validated 注解校验注解才会生效。
public class RoleController {

    @Resource
    private RoleService roleService;

    // 角色列表分页。
    @ApiOperation(value = "角色列表", notes = "")
    @GetMapping("/list")
    public MyResult<List<?>> list(PageQueryDTO pageQueryDTO, RoleDTO roleDTO) {
        return roleService.list(pageQueryDTO, roleDTO);
    }


    // 添加。
    @ApiOperation(value = "添加角色", notes = "")
    @PostMapping("/add")
    public MyResult<String> add(@RequestBody @Valid RoleDTO dto) {
        return roleService.add(dto);
    }


    // 修改。
    @ApiOperation(value = "修改角色", notes = "")
    @PostMapping("/edit")
    public MyResult<String> edit(@RequestBody @Valid RoleDTO dto) {
        return roleService.edit(dto);
    }

    // 删除。
    @ApiOperation(value = "单条删除", notes = "")
    @DeleteMapping("/delete/{id}")
    public MyResult<String> delete(@PathVariable String id) {
        return roleService.delete(id);
    }

    // 批量删除。
    @ApiOperation(value = "批量删除", notes = "")
    @DeleteMapping("/delete")
    public MyResult<String> deleteList(@RequestBody @Validated DeleteDTO<String> dto) {
        return roleService.deleteList(dto);
    }
}
